using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter02
{
	/// <summary>
	/// Example12: Not a Bad Throw for a Rookie!
	/// A stone thrown from the top of a building is given an 
	/// initial velocity of 20.0 m/s straight upward. The building 
	/// is 50.0 m high, and the stone just misses the edge of the 
	/// roof on its way down, as shown in Figure 2.14. 
	/// Using t_A = 0 as the time the stone leaves the thrower's 
	/// hand at position A, determine 
	/// (A) the time at which the stone reaches its maximum height, 
	/// (B) the maximum height, 
	/// (C) the time at which the stone returns to the height 
	/// from which it was thrown, 
	/// (D) the velocity of the stone at this instant, and 
	/// (E) the velocity and position of the stone at t = 5.00 s.
	/// </summary>
	public class Example12
	{
		public Example12()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Velocity v0 = new L.Velocity();
			v0.Z = 20.0;
			Science.Mathematics.Calculus.PolynomialFunction p = new Science.Mathematics.Calculus.PolynomialFunction();
			p.MaximumPower = 1;
			p.Which = 0;
			p.Coefficient = v0.Z;
			p.Which = 1;
			p.Coefficient = - L.Constant.AccelerationOfGravity;
			//(A)
			p.FindRoot();
			result += Convert.ToString(p.Root[0].Real)+"\r\n";
			//(B)
			result += Convert.ToString(v0.Z*p.Root[0].Real 
				- 0.5*L.Constant.AccelerationOfGravity
				*p.Root[0].Real*p.Root[0].Real)+"\r\n";
			//(C)
			result += Convert.ToString(2.0*p.Root[0].Real)+"\r\n";
			//(D)
			result += Convert.ToString(-v0.Z)+"\r\n";
			//(E)
			result += Convert.ToString(v0.Z - 
				L.Constant.AccelerationOfGravity*5.0)+"\r\n";
			result += Convert.ToString(0.0+v0.Z*5.0 
				- 0.5*L.Constant.AccelerationOfGravity
				*5.0*5.0)+"\r\n";
		}
	}
}
